//
//  MyTabBar.m
//  ExploreWorld
//
//  Created by 王凯 on 15/7/16.
//  Copyright (c) 2015年 chenlin. All rights reserved.
//

#import "MyTabBar.h"
#import "Header.h"

@interface MyTabBar ()

@property (nonatomic, retain) UIButton *Select;
//@property (nonatomic, retain) UIView *myTabBar;

@end

@implementation MyTabBar

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tabBar removeFromSuperview];
    
    self.myTabBar = [[UIView alloc] init];
    self.myTabBar.frame = CGRectMake(0, HEIGHT - 50, WIDTH, 50);
    self.myTabBar.backgroundColor = [UIColor colorWithRed:19 / 255.0 green:158 / 255.0 blue:238 / 255.0 alpha:1];
    [self.view addSubview:self.myTabBar];

    UIButton *NewImg = [UIButton buttonWithType:UIButtonTypeCustom];
    NewImg.frame = CGRectMake(WIDTH / 12 + 2, 0, WIDTH / 11, 30);
    [NewImg setImage:[UIImage imageNamed:@"iconfont-xinwen"] forState:UIControlStateNormal];
    NewImg.tag = 1000;
    [NewImg setTitleColor:[UIColor cyanColor] forState:UIControlStateSelected];
    [NewImg addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.myTabBar addSubview:NewImg];
    [NewImg release];
    
    UIButton *NewsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    NewsButton.frame = CGRectMake(WIDTH / 12, 25, WIDTH / 10, 25);
    [NewsButton setTitle:@"新闻" forState:UIControlStateNormal];
    NewsButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    NewsButton.tag = 1000;
    NewsButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [NewsButton addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.myTabBar addSubview:NewsButton];
    
    UIButton *ReadImg = [UIButton buttonWithType:UIButtonTypeCustom];
    ReadImg.frame = CGRectMake(WIDTH * 3 / 9 + 2, 0, WIDTH / 11, 30);
    [ReadImg setImage:[UIImage imageNamed:@"readimg"] forState:UIControlStateNormal];
    [self.myTabBar addSubview:ReadImg];
    ReadImg.tag = 2000;
    [ReadImg addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *ReadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    ReadButton.frame = CGRectMake(WIDTH / 9 * 3, 25, WIDTH / 10, 25);
    
    [ReadButton setTitle:@"阅读" forState:UIControlStateNormal];
    ReadButton.tag = 2000;
    ReadButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [ReadButton addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.myTabBar addSubview:ReadButton];
    
    UIButton *VideoImg = [UIButton buttonWithType:UIButtonTypeCustom];
    VideoImg.frame = CGRectMake(WIDTH / 9 * 5 + 2, 0, WIDTH / 11, 30);
    VideoImg.tag = 3000;
    [VideoImg setImage:[UIImage  imageNamed:@"iconfont-zhuishipin"] forState:UIControlStateNormal];
    [self.myTabBar addSubview:VideoImg];
    [VideoImg addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *VideoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    VideoButton.frame = CGRectMake(WIDTH / 9 * 5, 25, WIDTH / 10, 25);
    [VideoButton setTitle:@"试听" forState:UIControlStateNormal];
    VideoButton.tag = 3000;
    VideoButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    [VideoButton setTitleColor:[UIColor cyanColor] forState:UIControlStateSelected];
    [VideoButton addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.myTabBar addSubview:VideoButton];
    
    

    
    UIButton *SetImg = [UIButton buttonWithType:UIButtonTypeCustom];
    SetImg.frame = CGRectMake(WIDTH / 12 * 9.5 + 2, 3 , 30, 25);
    SetImg.tag = 4000;
    [SetImg setImage:[UIImage  imageNamed:@"iconfont-shezhi"] forState:UIControlStateNormal];
    [self.myTabBar addSubview:SetImg];
    [SetImg addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *SetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    SetButton.frame = CGRectMake(WIDTH / 12 * 9.5, 25, 30, 25);
    [SetButton setTitle:@"设置" forState:UIControlStateNormal];
    SetButton.tag = 4000;
    SetButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    [SetButton setTitleColor:[UIColor cyanColor] forState:UIControlStateSelected];
    [SetButton addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.myTabBar addSubview:SetButton];
    
    // 第一次 按钮所在位置
    [self random:NewsButton];
}

-(void)random:(UIButton *)button
{
    //让当前选中的按钮取消选中
    
    self.Select.selected = NO;
    
    //让新点击的按钮选中
    
    button.selected = YES;
    
    //新点击的按钮就成为了当前选中的按钮
    
    self.Select = button;
    
    
    //控制器连接按钮
    self.selectedIndex = button.tag / 1000 - 1;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
